package com.load.factories;

import java.util.List;

import com.database.objects.*;

public class DataFactory {

	public static Data createData(Project project, List<FileOO> files) {
		int numCommits = project.getVersionRepository().getAllEntries().size();
		int numFiles = files.size();
		int numClasses = countClasses(files);
		int numMethods = countMethods(files);
		int numLines = countLines(files);
		String startDate = project.getVersionRepository().getStartDate();

		return new Data(numCommits, numFiles, numClasses, numMethods, numLines, startDate);
	}

	private static int countClasses(List<FileOO> files) {
		int numClasses = 0;
		for (FileOO file : files) {
			numClasses += file.getNumberChilds();
		}
		return numClasses;
	}

	private static int countMethods(List<FileOO> files) {
		int numMethods = 0;
		for (FileOO file : files) {
			for (Element<?, ?> element : file.getChilds()) {
				numMethods += element.getNumberChilds();
			}
		}
		return numMethods;
	}

	private static int countLines(List<FileOO> files) {
		int numLines = 0;
		for (FileOO file : files) {
			for (Element<?, ?> elementClass : file.getChilds()) {
				for (Element<?, ?> elementMethod : elementClass.getChilds()) {
					numLines += elementMethod.getNumberChilds();
				}
			}
		}
		return numLines;
	}

}